package com.njupt.towersusers.controller;

import com.njupt.towersusers.domain.Drivers;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/usr")
@CrossOrigin("*")
public class DriverCtrl {

    @RequestMapping("/insertUsers")
    public String insert(
            Drivers driver,
            MultipartFile usphoto,
            MultipartFile drivercard
            ){
        return "{\"driverreg\": \"success\"}";
    }

    @RequestMapping("/userdel/{driverid}")
    public String del(@PathVariable("driverid") int driverid){
        System.out.println(driverid);
        return "{\"driverdestory\": \"success\"}";
    }

    @RequestMapping("/userMod")
    public String mod(Drivers drivers){
        return "{\"drivermodify\": \"success\"}";
    }

    @RequestMapping("/findUser")
    public List<Drivers> findUser(int pageSize,int pageNum){
        List<Drivers> drs = new ArrayList<>();
        drs.add(Drivers.builder().drivername("zs").driverid(12)
                .driverago(40).build());
        drs.add(Drivers.builder().drivername("ls").driverid(22)
                .driverago(50).build());
        return drs;
    }

    @RequestMapping("/findUserByConditition")
    public List<Drivers> findCond(Drivers drivers){
        List<Drivers> drs = new ArrayList<>();
        drs.add(Drivers.builder().drivername("zs").driverid(12)
                .driverago(40).build());
        drs.add(Drivers.builder().drivername("ls").driverid(22)
                .driverago(50).build());
        return drs;
    }
}
